package com.patzn.osgi.hello.configuration.admin;

import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;

import java.io.IOException;
import java.util.Dictionary;

/**
 * @name: ConfigurationAdminDemo
 * @description: ConfigurationAdminDemo
 * @author: jiangcs
 */
public class ConfigurationAdminDemo {
    private ConfigurationAdmin configurationAdmin;

    public void init() {
        try {
            Configuration configuration = configurationAdmin.getConfiguration("osgi.dev");
            Dictionary<String, Object> properties = configuration.getProperties();
            System.out.println(properties);

            // 更新配置文件
            properties.put("name", "osgi-dev-update");
            properties.put("address", "qd");
            configuration.update(properties);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public ConfigurationAdmin getConfigurationAdmin() {
        return configurationAdmin;
    }

    public void setConfigurationAdmin(ConfigurationAdmin configurationAdmin) {
        this.configurationAdmin = configurationAdmin;
    }
}
